package com.common.tag;

import java.io.IOException;
import java.util.Date;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import com.common.util.DateFormatter;

public class FormatDateTimeExTag extends SimpleTagSupport {

	private Date date;

	private Date defaultDate;

	private String pattern;

	public void setPattern(String pattern) {
		this.pattern = pattern;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public void setDefaultDate(Date defaultDate) {
		this.defaultDate = defaultDate;
	}

	public void doTag() throws JspException, IOException {
		String value = "";
		if (date == null) {
			value = new DateFormatter(defaultDate).formatDate(pattern);
		} else {
			value = new DateFormatter(date).formatDate(pattern);
		}

		this.getJspContext().getOut().print(value);
	}
}
